﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace Gui.Functies.Takenlijst_windows
{
    public partial class Addtaak : UserControl
    {
        string naam;
        string status;
        int projectID;

        MySqlConnection grabConnection = new MySqlConnection("Server=qq-design.com;Port=3306;Database=cookicom0;Uid=cookicom0;pwd=pizzahut91");
        
        public Addtaak()
        {
            InitializeComponent();
        }

        public Addtaak(int projectnummer)
        {
            projectID = projectnummer;
            InitializeComponent();
        }

        public void saveTask()
        {
            MySqlCommand taken = new MySqlCommand("INSERT INTO taken (TaakID, Taak, ProjectID, Status)" + "VALUES ('','" + naam + "','" + projectID + "','" + status + "')", grabConnection);

            try
            {
                grabConnection.Open();
                taken.ExecuteNonQuery();
            }
            catch (MySqlException e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                grabConnection.Close();
                this.Controls.Clear();
                this.Controls.Add(new Takenlijst(projectID));
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            naam = textBox1.Text;
            status = comboBox1.SelectedItem.ToString();

            if (naam != "" && status != "")
            {
                saveTask();
            }
            else
            {
                MessageBox.Show("Niet alle velden zijn ingevuld!");
            }
        }
    }
}
